package com.app.micaihu.view.login.activity

import android.os.Bundle
import android.text.Editable
import android.text.TextWatcher
import com.app.base.BaseMvpActivity
import com.app.http.bean.BaseBean
import com.app.micaihu.R
import com.app.micaihu.configure.Config
import com.app.micaihu.view.login.contract.LogInContract
import com.app.micaihu.view.login.presenter.LogInPresenter
import com.app.micaihu.view.set.AliFeedBackActivity
import com.blankj.utilcode.util.ToastUtils
import kotlinx.android.synthetic.main.login_forget_pass_activity.*

/**
 * Created by Guo on 2016/7/13.
 * 忘记密码
 */
class ForgetPasswordActivity : BaseMvpActivity<LogInContract.View, LogInPresenter>(), LogInContract.View {

    override fun getPresenter() = LogInPresenter()

    override fun getLayoutId() = R.layout.login_forget_pass_activity

    override fun setData() {

    }

    override fun addListeners() {
        tvLogin.setOnClickListener {
            mPresenter?.checkMobile(etPhone.text.toString())
        }

        etPhone.addTextChangedListener(object : TextWatcher {
            override fun afterTextChanged(s: Editable?) {
                tvLogin.isEnabled = etPhone.text.toString().isNotEmpty()
            }

            override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {
            }

            override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
            }

        })

        tvFeed.setOnClickListener {
            enterPager(AliFeedBackActivity::class.java)
        }
    }

    override fun handleCheckMobile(result: BaseBean<Any?>?) {
        if (result == null) {
            ToastUtils.showShort(getString(R.string.net_error))
        } else {
            if (result.isSuccess()) {
                val bundle = Bundle()
                bundle.putString(Config.Extra.phone, etPhone.text.toString())
                enterPager(ForgetPasswordConfirmActivity::class.java, bundle)
            } else {
                ToastUtils.showShort(result.msg)
            }
        }

    }

}